package com.sky.service.common;

import com.sky.result.Result;
import com.sky.utils.AliOssUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.UUID;

@Service
public class CommonServiceImpl implements CommonService{
    @Autowired
    private AliOssUtil aliOssUtil;
    @Override
    public Result upload(MultipartFile file) throws IOException {
        String fileName = "";
        String originalFilename = file.getOriginalFilename();
        String substring = originalFilename.substring(originalFilename.lastIndexOf("."));
        fileName = UUID.randomUUID().toString().replaceAll("-","")+substring;
        String upload = aliOssUtil.upload(file.getBytes(), fileName);
        return Result.success(upload);
    }
}
